Skip to content

Conversation

@SimplyLiz
Copy link
Owner

@SimplyLiz SimplyLiz commented Jan 31, 2026

Summary

Adds 4 new refactoring analysis features to CKB v8.1, building on the batch 1 foundation (feature/v8.1-refactoring-tools):

  • Dependency cycle detection (findCycles): Tarjan's SCC algorithm detects circular dependencies at module/directory/file granularity, with break-cost analysis suggesting which edge to remove
  • Move/relocate change type: Adds move to prepareChange and planRefactor with import scanning (SCIP-precise or heuristic fallback) and target conflict detection
  • Extract variable flow analysis: Tree-sitter-based parameter/return detection for extract refactorings with CGO graceful degradation
  • Suggested refactoring detection (suggestRefactorings): Proactive detection combining complexity, coupling, dead code, and audit analyzers in parallel to surface prioritized opportunities

Includes batch 1 changes (not yet merged to develop).

24 files changed (16 new, 8 modified), +3,115 lines, 51 new tests

New files

Feature Files
Cycles cycles/detector.go, query/cycles.go, mcp/tool_impls_cycles.go
Move query/prepare_move.go
Extract flow extract/types.go, extract/analyzer.go, extract/stub.go
Suggestions suggest/types.go, suggest/analyzer.go, query/suggest.go, mcp/tool_impls_suggest.go
Tests cycles/detector_test.go, query/cycles_test.go, query/prepare_move_test.go, query/prepare_extract_test.go, suggest/analyzer_test.go

Modified files

mcp/presets.go, mcp/presets_test.go, mcp/token_budget_test.go, mcp/tool_impls_compound.go, mcp/tools.go, query/compound.go, query/compound_refactor.go, query/prepare_extract.go

Test plan

  • go build ./cmd/ckb passes
  • go test ./internal/... — full suite passes (57 packages)
  • gofmt -l clean on all new/modified files
  • 12 tests: Tarjan's SCC — empty, DAG, simple/triangle/large cycles, multiple cycles, max limit, edge meta, break cost, self-loops
  • 12 tests: Suggest helpers — severity ranking, filtering, dedup, summary, thresholds, file listing
  • 7 tests: Graph extraction — module/directory/file granularity, resolved edges, empty input, cycle summary
  • 9 tests: Move analysis — target conflicts, heuristic import scanning, nil/empty guards
  • 11 tests: Extract analysis — language inference, Go/JS/Python signature generation, boundary analysis
  • Integration: findCycles with granularity=directory returns cycle data or empty result
  • Integration: prepareChange with changeType: "move" returns MoveDetail
  • Integration: prepareChange with changeType: "extract" returns populated Parameters/Returns (CGO)
  • Integration: suggestRefactorings with a target scope returns prioritized suggestions

🤖 Generated with Claude Code

SimplyLiz and others added 2 commits January 31, 2026 13:14
Five features based on Cursor agent feedback from live refactoring trial:

1. Function-level complexity in auditRisk — wire tree-sitter complexity
   analyzer into audit, returning per-function cyclomatic+cognitive scores
   sorted by complexity (top 10 per file). Falls back to heuristic.

2. Graceful degradation messaging — new DegradationWarning type with
   capability percentages and fix commands. Wired into explore, understand,
   prepareChange, auditRisk, and findDeadCode MCP handlers.

3. Test gap analysis — new testgap package + analyzeTestGaps MCP tool.
   Cross-references complexity analysis with SCIP references or heuristic
   name matching to identify untested functions, sorted by risk.

4. Richer prepareChange for rename/extract — RenameDetail (call sites,
   type refs, imports with context snippets) and ExtractDetail (boundary
   analysis) added as parallel goroutines in PrepareChange.

5. Unified planRefactor compound tool — aggregates prepareChange + auditRisk
   + analyzeTestGaps in parallel, generates ordered refactoring steps by
   change type (rename/extract/delete/modify).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Four new features extending the refactoring toolset:

1. Dependency cycle detection (findCycles) - Tarjan's SCC algorithm to
   detect circular dependencies at module/directory/file granularity,
   with break-cost analysis suggesting which edge to remove.

2. Move/relocate change type - adds "move" to prepareChange and
   planRefactor, scanning for affected imports (SCIP-precise or
   heuristic fallback) and target path conflicts.

3. Extract variable flow analysis - tree-sitter-based parameter/return
   detection for extract refactorings, with CGO/non-CGO build tags
   for graceful degradation.

4. Suggested refactoring detection (suggestRefactorings) - proactive
   detection combining complexity, coupling, dead code, and audit
   analyzers in parallel to surface prioritized opportunities.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Jan 31, 2026

🟡 Change Impact Analysis

Metric Value
Risk Level MEDIUM 🟡
Files Changed 37
Symbols Changed 678
Directly Affected 1
Transitively Affected 246

Blast Radius: 0 modules, 1 files, 247 unique callers

📝 Changed Symbols (678)
Symbol File Type Confidence
AnalyzeOptions internal/query/suggest.go added 100%
AnalyzeOptions internal/extract/analyzer.go added 100%
AnalyzeOptions internal/query/testgap.go added 100%
AnalyzeOptions#EndLine internal/extract/analyzer.go added 100%
AnalyzeOptions#Language internal/extract/analyzer.go added 100%
AnalyzeOptions#Limit internal/query/suggest.go added 100%
AnalyzeOptions#Limit internal/query/testgap.go added 100%
AnalyzeOptions#MinLines internal/query/testgap.go added 100%
AnalyzeOptions#MinSeverity internal/query/suggest.go added 100%
AnalyzeOptions#Scope internal/query/suggest.go added 100%
AnalyzeOptions#Source internal/extract/analyzer.go added 100%
AnalyzeOptions#StartLine internal/extract/analyzer.go added 100%
AnalyzeOptions#Target internal/query/testgap.go added 100%
AnalyzeOptions#Types internal/query/suggest.go added 100%
AnalyzeTestGapsOptions internal/mcp/tool_impls_testgap.go added 100%
+663 more
🎯 Affected Downstream (20)
Symbol Module Distance Kind
unknown `` 1 type-dependency
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_EmptySource(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_Go_AllLocals(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_Go_BasicFlow(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_Go_ParameterAndReturnDetection(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_JavaScript_BasicFlow(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_NoContainingFunction(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_Python_BasicFlow(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/mcp/MCPServer#RegisterTools(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/mcp/MCPServer#toolAnalyzeTestGaps(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/mcp/MCPServer#toolPlanRefactor(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/mcp/MCPServer#toolSuggestRefactorings(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/query/Engine#AnalyzeTestGaps(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/query/Engine#PlanRefactor(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/query/Engine#PrepareChange(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/query/Engine#SuggestRefactorings(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/query/TestGetPrepareExtractDetail_EmptyPath(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/query/TestGetPrepareExtractDetail_NilTarget(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/query/TestGetPrepareExtractDetail_NonexistentFile(). `` 2 transitive-caller
scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/query/TestGetPrepareExtractDetail_WithFile(). `` 2 transitive-caller

Recommendations

  • ⚠️ test: Significant transitive impact (246 symbols). Run comprehensive test suite.
    • Action: Run full test suite before merging

⚠️ Index is 0 commit(s) behind HEAD. Results may be incomplete.


Generated by CKB

@github-actions
Copy link

github-actions bot commented Jan 31, 2026

🔐 Security Audit Results

⚠️ Security gate passed with warnings - 7 issue(s) found (review recommended)

Category Findings
🔑 Secrets ✅ 0
🛡️ SAST ✅ 0
📦 Dependencies ⚠️ 7
📜 Licenses ⚠️ 144 non-permissive

📦 Dependency Vulnerabilities

Found 7 vulnerability(ies) across 2 scanner(s)

Details

Trivy (4 findings)

  • CVE-2026-22036 (MEDIUM): undici - undici: Undici: Denial of Service via excessive de...
  • CVE-2025-54410 (LOW): github.com/docker/docker - github.com/moby/moby: Moby's Firewalld reload remo...
  • GHSA-vrw8-fxc6-2r93 (MEDIUM): github.com/go-chi/chi/v5 - chi Allows Host Header Injection which Leads to Op...
  • CVE-2025-47908 (MEDIUM): github.com/rs/cors - github.com/rs/cors: Denial of service via maliciou...

OSV-Scanner (3 findings)

  • github.com/docker/docker: 2 vulnerabilities
  • github.com/go-chi/chi/v5: 1 vulnerabilities
  • github.com/rs/cors: 2 vulnerabilities

📜 License Issues

Found 144 non-permissive license(s)

Details
  • github.com/BurntSushi/toml: MIT (notice)
  • github.com/google/uuid: BSD-3-Clause (notice)
  • github.com/klauspost/compress: Apache-2.0 (notice)
  • github.com/klauspost/compress: BSD-3-Clause (notice)
  • github.com/klauspost/compress: MIT (notice)
  • github.com/pelletier/go-toml/v2: MIT (notice)
  • github.com/smacker/go-tree-sitter: MIT (notice)
  • github.com/sourcegraph/go-diff: MIT (notice)
  • github.com/sourcegraph/scip: Apache-2.0 (notice)
  • github.com/spf13/cobra: Apache-2.0 (notice)
  • ... and 134 more

Generated by CKB Security Audit | View Details | Security Tab

@codecov
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

❌ Patch coverage is 59.51991% with 742 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/suggest/analyzer.go 53.6% 142 Missing and 12 partials ⚠️
internal/testgap/analyzer.go 12.3% 140 Missing and 2 partials ⚠️
internal/query/compound_refactor.go 37.1% 105 Missing and 15 partials ⚠️
internal/query/prepare_rename.go 0.0% 70 Missing ⚠️
internal/query/prepare_move.go 63.1% 32 Missing and 6 partials ⚠️
internal/audit/analyzer.go 21.0% 30 Missing ⚠️
internal/mcp/tool_impls_compound.go 50.0% 25 Missing and 5 partials ⚠️
internal/query/compound.go 25.0% 24 Missing and 3 partials ⚠️
internal/mcp/tool_impls_testgap.go 0.0% 25 Missing ⚠️
internal/query/prepare_extract.go 82.0% 16 Missing and 5 partials ⚠️
... and 9 more
Additional details and impacted files
@@            Coverage Diff            @@
##           develop    #128     +/-   ##
=========================================
+ Coverage     44.9%   45.5%   +0.5%     
=========================================
  Files          350     365     +15     
  Lines        60028   61829   +1801     
=========================================
+ Hits         27004   28165   +1161     
- Misses       31188   31761    +573     
- Partials      1836    1903     +67     
Flag Coverage Δ
unit 45.5% <59.5%> (+0.5%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link

github-actions bot commented Jan 31, 2026

CKB Analysis

Risk Files +5806 -65 Modules

🎯 678 changed → 246 affected · 🔥 13 hotspots · 📊 9 complex · 💣 10 blast · 📚 143 stale

Risk factors: Large PR with 37 files • High churn: 5871 lines changed • Touches 13 hotspot(s)

Metric Value
Impact Analysis 678 symbols → 246 affected 🟡
Doc Coverage 9.090909090909092% ⚠️
Complexity 9 violations ⚠️
Coupling 0 gaps
Blast Radius 0 modules, 1 files
Index indexed (7s) 💾
🎯 Change Impact Analysis · 🟡 MEDIUM · 678 changed → 20 affected
Metric Value
Symbols Changed 678
Directly Affected 1
Transitively Affected 246
Modules in Blast Radius 0
Files in Blast Radius 1

Symbols changed in this PR:

Downstream symbols affected:
Direct callers (1):

  • unknown
    Transitive callers (19):
  • scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_EmptySource(). (depth 2)
  • scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_Go_AllLocals(). (depth 2)
  • scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_Go_BasicFlow(). (depth 2)
  • scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_Go_ParameterAndReturnDetection(). (depth 2)
  • scip-go gomod github.com/SimplyLiz/CodeMCP ad508827d3be github.com/SimplyLiz/CodeMCP/internal/extract/TestAnalyze_JavaScript_BasicFlow(). (depth 2)
  • … and 14 more transitive callers

Recommendations:

  • ⚠️ Significant transitive impact (246 symbols). Run comprehensive test suite.
    • Action: Run full test suite before merging

⚠️ Index is undefined commit(s) behind HEAD. Results may be incomplete. Run ckb index to refresh.

💣 Blast radius · 0 symbols · 10 tests · 0 consumers

Tests that may break:

  • internal/audit/audit_test.go
  • internal/cycles/detector_test.go
  • internal/extract/analyzer_test.go
  • internal/mcp/presets_test.go
  • internal/mcp/token_budget_test.go
  • … and 5 more
🔥 Hotspots · 13 volatile files
File Churn Score
CHANGELOG.md 9.54
internal/audit/analyzer.go 6.44
internal/cycles/detector.go 5.57
internal/extract/analyzer.go 7.89
internal/mcp/presets.go 6.50
internal/mcp/tool_impls_compound.go 10.57
internal/mcp/tools.go 10.77
internal/query/compound.go 13.88
📦 Modules · 2 at risk
Module Files
🔴 internal/query 12
🔴 internal/mcp 11
📊 Complexity · 9 violations
File Cyclomatic Cognitive
internal/audit/analyzer.go ⚠️ 19 ⚠️ 49
internal/cycles/detector.go ⚠️ 19 ⚠️ 45
internal/cycles/detector_test.go 14 ⚠️ 22
internal/extract/analyzer.go ⚠️ 21 ⚠️ 45
internal/mcp/presets_test.go ⚠️ 21 ⚠️ 35
internal/mcp/token_budget_test.go 10 ⚠️ 24
internal/mcp/tool_impls_compound.go ⚠️ 16 ⚠️ 28
internal/mcp/tool_impls_deadcode.go ⚠️ 19 ⚠️ 32
💡 Quick wins · 10 suggestions
📚 Stale docs · 143 broken references

Generated by CKB · Run details

SimplyLiz and others added 5 commits January 31, 2026 17:12
- cycles/detector_test.go: Tarjan SCC algorithm, break cost, severity
- query/cycles_test.go: graph extraction, cycle summary
- query/prepare_move_test.go: target conflicts, heuristic import scanning
- query/prepare_extract_test.go: signature generation, language inference
- suggest/analyzer_test.go: severity helpers, dedup, file listing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add CHANGELOG entries for cycle detection, move/relocate, extract flow
analysis, and suggested refactoring detection. Add 23 MCP integration
tests for all batch 2 features.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Cover the previously untested extract/analyzer.go with CGO-tagged tests:
- Full Analyze() pipeline for Go, JavaScript, and Python source
- classifyVariables() logic: parameter/return/local classification,
  modified tracking, empty input, unused-in-region exclusion
- AST walking: findContainingFunction, collectDeclarations,
  collectReferences, keyword filtering
- Helper functions: isKeyword, langToExtension, node type helpers

Documents known limitation: Go assignment_statement wraps LHS in
expression_list, so `x = expr` doesn't trigger isModified detection.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- extract/analyzer.go: return parse error instead of nil (nilerr),
  remove unused strings import and lines variable
- suggest/analyzer.go: propagate filepath.Walk errors instead of
  swallowing them (nilerr)
- prepare_move_test.go: use context.TODO() instead of nil context
  (staticcheck SA1012)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The extract flow analyzer always operated on the entire file because
startLine/endLine were never passed from MCP through to the analyzer.
This made parameter/return detection useless since all variables are
both defined and used within the same (whole-file) range.

Adds startLine/endLine to prepareChange MCP tool definition, parses
them in the handler, and threads them through PrepareChangeOptions
and PlanRefactorOptions to getPrepareExtractDetail.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@SimplyLiz SimplyLiz merged commit 575bc03 into develop Jan 31, 2026
22 checks passed
@SimplyLiz SimplyLiz deleted the feature/v8.1-refactoring-batch2 branch January 31, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants